package delegate4j;

import com.sun.istack.internal.Nullable;

import java.util.concurrent.FutureTask;

@FunctionalInterface
public interface IFunc8<T1, T2, T3, T4, T5, T6, T7, T8, TResult> extends IDelegate {

    TResult invoke(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) throws Exception;

    default FutureTask<TResult> invokeAsync(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, @Nullable Callback callback) {
        FutureTask<TResult> futureTask = new FutureTask<>(() -> {
            TResult result = invoke(t1, t2, t3, t4, t5, t6, t7, t8);
            if (callback != null) {
                callback.invoke(new InvokeData(this, new Object[]{t1, t2, t3, t4, t5, t6, t7, t8}, result));
            }
            return result;
        });

        ASYNC_DELEGATE_THREAD_POOL.submit(futureTask);
        return futureTask;
    }

}
